<?php
	/**
	 * REMOVE CATEGORY LINK FROM POST SCREEN
	 */
	add_action('add_meta_boxes', 'hide_categories_metabox');
	function hide_categories_metabox()
	{
		//remove categories box
		remove_meta_box('categorydiv', 'post', 'side');
		//remove feature image box
		remove_meta_box('postimagediv', 'post', 'side');
		//remove tag box
		remove_meta_box('tagsdiv-post_tag', 'post', 'side');
        //remove format box
        remove_meta_box('formatdiv', 'post', 'side');
        
	}
	add_action('admin_menu', 'dx_remove_menu_pages', 999);
	function dx_remove_menu_pages()
	{
		//remove_menu_page('upload.php');
		remove_submenu_page('edit.php', 'edit-tags.php?taxonomy=category');
	}

	/**
	 * CREATE DEAL METADATA
	 */
	add_action('admin_init', 'create_deal_metadata');
	function create_deal_metadata()
	{
		// Get stores
		$args = array(
			'post_type' => 'store',
			'post_status' => 'publish',
			'posts_per_page' => -1,
			'orderby' => 'title',
			'order' => 'ASC');

		$stores = get_posts($args);
		$arr_stores = array(array('label' => '', 'value' => 0));
		foreach ($stores as $v)
		{
			$t = array();
			$t['label'] = $v->post_title;
			$t['value'] = $v->ID;
			array_push($arr_stores, $t);
		}
		// Create metabox
		$deal_metabox = array(
			'id' => 'box_deal_metadata',
			'title' => 'Deal Meta Fields',
			'desc' => '',
			'pages' => array('post','product'),
			'context' => 'normal',
			'priority' => 'high',
			'fields' => array(
                // Cash back
                array(
					'id' => 'cashback_metadata',
					'label' => 'Moneyback Guarantee',
					'desc' => 'days',
					'std' => '',
					'type' => 'text',
					'class' => '',
					'choices' => array()),
				// select store
				array(
					'id' => 'store_id_metadata',
					'label' => 'Select store',
					'desc' => '',
					'std' => '',
					'type' => 'select',
					'class' => '',
					'choices' => $arr_stores),
				// value
				array(
					'id' => 'value_metadata',
					'label' => 'Value',
					'desc' => '$',
					'std' => 0,
					'type' => 'text',
					'class' => '',
					'choices' => array()),
				// discount percent
				array(
					'id' => 'discount_metadata',
					'label' => 'Discount',
					'desc' => 'Percent (%)',
					'std' => '',
					'type' => 'text',
					'class' => '',
					'choices' => array()),
				// Value after discount
				array(
					'id' => 'after_discount_metadata',
					'label' => 'Value after discount',
					'desc' => '$',
					'std' => '',
					'type' => 'text',
					'class' => '',
					'choices' => array()),
				// $ saving
				array(
					'id' => 'save_metadata',
					'label' => 'Save',
					'desc' => '$',
					'std' => '',
					'type' => 'text',
					'class' => '',
					'choices' => array()),
				// start date
				array(
					'id' => 'start_date_metadata',
					'label' => 'Start date',
					'desc' => 'format : yyyy/mm/dd',
					'std' => '',
					'type' => 'text',
					'class' => '',
					'choices' => array()),
				// end date
				array(
					'id' => 'end_date_metadata',
					'label' => 'End date',
					'desc' => 'format : yyyy/mm/dd',
					'std' => '',
					'type' => 'text',
					'class' => '',
					'choices' => array()),
				// active / deactive
				array(
					'id' => 'status_metadata',
					'label' => 'Status',
					'desc' => '',
					'std' => 'active',
					'type' => 'radio',
					'class' => '',
					'choices' => array(array('label' => 'Active', 'value' => 'active'), array('label' => 'Deactive',
								'value' => 'deactive'))),
                // certificate
                    array(
    					'id' => 'certificate_metadata',
    					'label' => 'Display Certificate',
    					'desc' => '',
    					'std' => '',
    					'type' => 'radio',
    					'class' => '',
    					'choices' => array(
                        array('label' => 'None', 'value' => ''),
                        array('label' => 'Avangate', 'value' => 'adv'), 
                        array('label' => 'MyCommerce', 'value' => 'myc')))                
                ));
				
        $deal_mainlink_metabox = array(
			'id' => 'box_mainlink_metadata',
			'title' => 'Primary Checkout Link',
			'desc' => '',
			'pages' => array('post','product'),
			'context' => 'normal',
			'priority' => 'high',
			'fields' => array(
            // text
				array(
					'id' => 'link_checkout_text_metadata',
					'label' => 'Display Text',
					'desc' => '',
					'std' => '',
					'type' => 'text',
					'class' => '',
					'choices' => array()),
            // link to checkout
				array(
					'id' => 'link_checkout_metadata',
					'label' => 'Link to checkout',
					'desc' => '',
					'std' => '',
					'type' => 'text',
					'class' => '',
					'choices' => array())
            ));
		$deal_extra_metabox = array(
			'id' => 'box_extra_metadata',
			'title' => 'Deal Extra Versions',
			'desc' => '',
			'pages' => array('post','product'),
			'context' => 'normal',
			'priority' => 'high',
			'fields' => array(
					array(
					'id' => 'extra_metadata',
					'label' => '',
					'desc' => '',
					'std' => '',
					'type' => 'textarea',
					'class' => '',
					'choices' => array())                    
                    ));
        $short_desc = array(
			'id' => 'box_shortdesc_metadata',
			'title' => 'Short Description',
			'desc' => '',
			'pages' => array('post','product'),
			'context' => 'normal',
			'priority' => 'high',
			'fields' => array(
				// short desc
				array(
					'id' => 'short_desc_metadata',
					'label' => 'Short Description',
					'desc' => '',
					'std' => '',
					'type' => 'textarea',
					'class' => '',
					'choices' => array())                
                    ));
        $logo = array(
			'id' => 'box_logo_metadata',
			'title' => 'Feature image',
			'desc' => '',
			'pages' => array('post','product'),
			'context' => 'normal',
			'priority' => 'high',
			'fields' => array(
				// Deal feature image
				array(
					'id' => 'deal_feature_metadata',
					'label' => 'Deal feature image',
					'desc' => '',
					'std' => '',
					'type' => 'upload',
					'class' => '',
					'choices' => array())));
        
        ot_register_meta_box($short_desc);
        ot_register_meta_box($logo);
        ot_register_meta_box($deal_mainlink_metabox);
		ot_register_meta_box($deal_metabox);
        ot_register_meta_box($deal_extra_metabox);
	}
?>